*** Settings ***
Library           RequestsLibrary
Resource           ../common/common.robot
Library           JSONLibrary

*** Keywords ***

Get Role
    [Arguments]     ${role_id}
    ${header}    Create Header
    Create Session    get_role    ${host}
    ${data}    Create Dictionary    id=${role_id}
    ${response}    POST On Session    get_role    /api/admin/account/role/get.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态
    Should Be Equal As Strings    ${response.json()['message']}    OK       # 校验接口状态
    RETURN    ${response.json()['data']}
Save Role
    [Arguments]     ${data}
    ${header}    Create Header
    Create Session    save_role    ${host}
    ${response}    POST On Session    save_role    /api/admin/account/role/add.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态
    Should Be Equal As Strings    ${response.json()['message']}    OK       # 校验接口状态
    RETURN    ${response.json()['data']}

Delete Role
    [Arguments]     ${role_id}
    ${header}    Create Header
    Create Session    delete_role    ${host}
    ${data}    Create Dictionary    id=${role_id}
    ${response}    POST On Session    delete_role    /api/admin/account/role/delete.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态
    Should Be Equal As Strings    ${response.json()['message']}    OK       # 校验接口状态
    RETURN    ${response.json()['data']}

Update User Role
    [Arguments]     ${data}
    ${header}    Create Header
    Create Session    update_user_role    ${host}
    ${response}    POST On Session    update_user_role    /api/admin/account/user/update.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态
    Should Be Equal As Strings    ${response.json()['message']}    OK       # 校验接口状态

Clear User Role
    [Arguments]
    [Documentation]     清空用户的所有角色
    ${data}    Load JSON from file    ./DEF-16742/data/update_user_role.json     UTF-8
    ${role_arr}     Create List
    # 清空角色占用
    ${data}    Update value to JSON     ${data}     $.roleIds      ${role_arr}
    Update User Role    ${data}

Update Role Assign MenuId
    [Arguments]     ${role_id}   ${menuid_arr}
    [Documentation]         更新指定用户的权限
    ${data}    Load JSON from file    ./DEF-16742/data/update_role_menu.json     UTF-8
    # 清空角色占用
    ${data}    Update value to JSON     ${data}     $.menuIds      ${menuid_arr}
    ${data}    Update value to JSON     ${data}     $.roleInfo.id      ${role_id}
    Update User Role    ${data}